package com.letoken.platform.admin.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.letoken.platform.pub.annotation.auth.Permission;
import com.letoken.platform.pub.annotation.pub.Trim;
import com.letoken.platform.pub.res.ApiResponse;
import com.letoken.platform.repo.admin.req.mall.AccelerateDetailReq;
import com.letoken.platform.repo.admin.req.mall.MallIssueRelordReq;
import com.letoken.platform.repo.admin.res.mall.AccelerateDetailRes;
import com.letoken.platform.repo.admin.res.mall.MallIssueRelordRes;
import com.letoken.platform.repo.admin.util.StringUtils;
import com.letoken.platform.repo.mall.dao.AppMallIssueRecordMapper;
import com.letoken.platform.repo.utlis.PageDataUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;
import java.util.regex.Pattern;

@RestController
@RequestMapping("/mallIssueRecordController")
@Api(tags = "商城发行查询")
public class MallIssueRecordController {
    @Resource
    private AppMallIssueRecordMapper appMallIssueRecordMapper;


    @Permission(uri = "/mallIssueRecordController/mallIssueAmout",qx = "/mallIssueRecordController/mallIssueAmout")
    @Trim
    @GetMapping("/mallIssueAmout")
    @ApiOperation(value = "发型记录-数据统计", notes = "发型记录-数据统计")
    public ApiResponse mallIssueAmout() {
        Map<String,BigDecimal> map = new HashMap<>();
        map.put("one",appMallIssueRecordMapper.getMallIssueAmout(0,"1"));
        map.put("two",appMallIssueRecordMapper.getMallIssueAmout(1,"1"));
        map.put("three",map.get("one").add(map.get("two")));
        map.put("four",appMallIssueRecordMapper.getMallIssueAmout(0,"2"));
        map.put("five",appMallIssueRecordMapper.getMallIssueAmout(1,"2"));
        map.put("six",map.get("four").add(map.get("five")));
        map.put("seven",appMallIssueRecordMapper.getMallIssueAmout(0,"3"));
        map.put("eight", appMallIssueRecordMapper.getMallIssueAmout(1,"3"));
        map.put("nine",map.get("seven").add(map.get("eight")));
        map.put("ten",appMallIssueRecordMapper.getMallIssueAmout(0,null));
        map.put("eleven",appMallIssueRecordMapper.getMallIssueAmout(1,null));
        map.put("twelve",map.get("eleven").add(map.get("eleven")));
        map.put("Thirteen",appMallIssueRecordMapper.getMallIssueAmoutWait());
        return ApiResponse.create(map);
    }



    @Trim
    @PostMapping ("/getMallIssueDetail")
    @Permission(uri = "/mallIssueRecordController/getMallIssueDetail",qx = "/mall/mallIssued")
    @ApiOperation(value = "发行记录", notes = "发行记录")
    public ApiResponse<Page<MallIssueRelordRes>> getMallIssueDetail(@RequestBody MallIssueRelordReq req) {
        Page<MallIssueRelordRes> page = new Page<>(req.getPageReq().getPage(), req.getPageReq().getSize());
        if(!req.getSeqNo().isEmpty()){
            if(req.getSeqNo().length()<15){
                req.setIssueType(1);
            }else {
                req.setIssueType(2);
            }
        }
        Page<MallIssueRelordRes> res = appMallIssueRecordMapper.getMallIssueDetail(page,req);
        return ApiResponse.create( PageDataUtil.getPageData(res, MallIssueRelordRes.class));
    }


    @Permission(uri = "/mallIssueRecordController/accelerate",qx = "/mallIssueRecordController/accelerate")
    @GetMapping("/accelerate")
    @ApiOperation(value = "加速时间统计", notes = "加速时间统计")
    public ApiResponse accelerate() {
        Map<String,BigDecimal> map = new HashMap<>();
        map.put("one",appMallIssueRecordMapper.getAccelerateTime("2"));
        map.put("two",appMallIssueRecordMapper.getAccelerateTime("1"));
        map.put("three",appMallIssueRecordMapper.getAccelerateTime("3"));
        map.put("four",appMallIssueRecordMapper.getAccelerateTime(null));
        return ApiResponse.create(map);
    }

    @Permission(uri = "/mallIssueRecordController/getAccelerateDetail",qx = "/mall/mallAccelerate")
    @Trim
    @PostMapping("/getAccelerateDetail")
    @ApiOperation(value = "加速记录", notes = "加速记录")
    public ApiResponse<Page<AccelerateDetailRes>> getAccelerateDetail(@RequestBody AccelerateDetailReq req) {
        Page<AccelerateDetailRes> page = new Page<>(req.getPageReq().getPage(), req.getPageReq().getSize());
        Page<AccelerateDetailRes> res = appMallIssueRecordMapper.getAccelerateDetail(page,req);
        return ApiResponse.create( PageDataUtil.getPageData(res, AccelerateDetailRes.class));
    }

}
